import axios from "axios";
// import { Message } from "element-ui";
const BASE_URL = "http://192.168.0.110/";
//const BASE_URL = "https://wx.jinbiaobiao.com";
// 创建axios实例
const service = axios.create({
  baseURL: BASE_URL,
  timeout: 15000
});
service.defaults.withCredentials = true; //生产环境要改为true
// axios.defaults.baseURL = "192.168.0.110:12359";
// axios.defaults.timeout = 8000;

// request拦截器
service.interceptors.request.use(
  config => {
    const token = window.localStorage.getItem("token");
    //console.log(token);
    if (token) {
      config.headers["usertoken"] = token;
      document.cookie = "usertoken=" + token;
    }
    return config;
  },
  error => {
    Promise.reject(error);
  }
);
//import { Toast } from "mint-ui";
import router from "../router";
// respone拦截器
service.interceptors.response.use(
  response => {
    //if (response.data.code !== 200) {
    // Message({
    //   message: response.data.msg,
    //   type: "error"
    // });
    //}
    if (response.data.code == 400) {
      //Toast("需要用户登录");
      router.push({ path: "/Login" });
    }
    return response.data;
  },
  error => {
    return Promise.reject(error);
  }
);
export default service;
